package com.PinZhuo.www.shouye;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.PinZhuo.www.BaseFragment;
import com.PinZhuo.www.MyFragmentAdapter;
import com.PinZhuo.www.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tukela on 2015/10/12.
 */
public class HomeFragment extends BaseFragment implements ViewPager.OnPageChangeListener, View.OnClickListener {
    private List<Fragment> fragmentList=new ArrayList<>();
    private View rootView;
    private ViewPager viewPager;
    private List<TextView> textViewList=new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView= inflater.inflate(R.layout.fragment_home,null);
        initView(rootView);
        viewPager= (ViewPager) rootView.findViewById(R.id.home_vp);
        viewPager.setOnPageChangeListener(this);
        viewPager.setAdapter(new MyFragmentAdapter(getChildFragmentManager(),fragmentList));

        return rootView;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fragmentList.add(new FragmentPinZhuoList());
        fragmentList.add(new FragmentShangJiaList());
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }


    private void initView(View view){
        textViewList.add((TextView) view.findViewById(R.id.menu_pinzhuo));
        textViewList.add((TextView) view.findViewById(R.id.menu_shangjia));
        setTextViewOnClickListenner(textViewList,this);
    }

    @Override
    public void onPageScrolled(int i, float v, int i1) {
//            setTextViewBc(textViewList,textViewList.get(i));
    }

    @Override
    public void onPageSelected(int i) {

    }

    @Override
    public void onPageScrollStateChanged(int i) {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.menu_pinzhuo:
                viewPager.setCurrentItem(0);
                break;
            case R.id.menu_shangjia:
                viewPager.setCurrentItem(1);
                break;
        }
        setTextViewBc(textViewList,v);
    }
}
